feat(runtime): expose typed request context to operation handlers and the test harness (#223) - #273
Conversation
🦋 Changeset detectedLatest commit: afde7a2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 765bb5528f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }; | ||
|
|
||
| export const currentAgentRequest = (): AgentRequestContext | undefined => { | ||
| const lease = getStore().storage.getStore(); |
There was a problem hiding this comment.
Avoid initializing the global store from the context probe
When defineOperation.execute runs outside an invocation, this probe now calls getStore(), which both creates the realm-wide Symbol.for('@agent-bundle/runtime/request-store') store and throws if another installed runtime version already owns it. Consequently, an otherwise context-free direct operation can either fail with store-version-conflict in a mixed-version process or claim the symbol and cause the other runtime to fail later, even though direct execution previously did not touch request storage. Make the non-throwing probe inspect an existing compatible store without creating or rejecting on an unrelated version.
Useful? React with 👍 / 👎.
765bb55 to
afde7a2
Compare
…tool scopes (#223) (#276) * feat(runtime): observe transport identity in generated MCP request scopes (#223) Generated MCP tool, resource, and prompt request scopes now observe the negotiated client identity as a native host and derive workspace from the server process cwd, alongside the existing native session and authInfo actor, forwarding all four axes into the Flight worker. Typed unavailability is preserved where a transport genuinely lacks an axis (bare stdio supplies no sessionId or authInfo). The in-memory projection level mirrors the worker boundary so mcp-in-memory stays faithful, with the harness context seam still winning. Proof assertions flip from honest absence to the positive contract at the generated-server integration, mcp-in-memory, and packed journey levels; also repairs the packed listTools assertion left stale when #273 added the context fixture route. * test(packed): reconcile packed listTools with the mutation-probe harness tool (#275)
Summary
Delivers the #223 handler-context slice:
defineOperationhandlers now receive the transport-installedAgentRequestContextas optionalcontext.requeston the secondexecuteargument — the identical handleawait agent()returns for that invocation (same ALS lease, no divergent snapshot). Identity axes stay honestObservedvalues:availablewith a source when the transport knows them,unavailablewith a typed reason when it cannot; nothing is fabricated, and business input can never override request identity.Contract
RscOperationContextgains optionalreadonly request?: AgentRequestContext(additive: existing single-argument handlers and directexecute(input, { signal })callers compile and behave unchanged). A caller-suppliedrequestwins; otherwise the wrapper resolves the live handle via a new non-throwing internal probecurrentAgentRequest(); outside any invocation the field stays absent.getClientVersion().name, sourcenative) alongside the existing nativesessionIdsession andauthInfo.clientIdactor. CLI keeps derived workspace + typedunavailable('unsupported-surface')host, now proven by test.await agent()path (the route graph retired the execute/render split via AB4811);ToolRouteProps/CliRouteProps/AgentEventRoutePropsanddocs/entry-conventions.mdnow document the context contract, including that generated event scopes mount no actor principal (typed absent, per the finding recorded on Track remaining #98 state-kernel scope: warm-runtime process state, generated-runtime state mounting, budgets, lifetime visibility #233).Harness spoof/injection surface
renderRoute(..., { context })is the documented identity-injection seam (host/session/actor/workspace/capabilities, built withavailable/unavailable).tool:harness/contextfixture route reports the observed axes; proofs cover: default typed-unavailable axes, injected axes with preserved sources, lookalike business-input fields not treated as identity, and event-route actor honestly absent.Honest transport findings encoded in tests
not-provided, not faked.Also includes a one-line repair of
state-packaging.test.ts: the #99 stage-3 merge (ef1bcdf) added the./notices/inbox-routeexport but missed the exports pin, leaving the runtime package tests red on latest main.Changeset: minor for
@agent-bundle/runtimeandagent-bundle.Gates (local, on the rebased branch)
pnpm build+pnpm typecheck— passpnpm lint— 0 errors / 0 warnings (929 files)pnpm --filter @agent-bundle/runtime test— 245 passed, 1 skipped, 0 failedpnpm test:route-unit— 18/18pnpm test:projection— 44/44Refs #223, #233, #251, #255.